<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    body {
      height: 2000px;
    }

    #ad {
      width: 300px;
      height: 400px;
      background: skyblue;
      position: fixed;
      bottom: -400px;
      right: 0;
    }
  </style>
</head>

<body>
  <div id="show">2020-12-20</div>
  <button id="btn">
    点击停止时间
  </button>
  <!-- -->
  <div id="ad">
    一刀999999
  </div>
  <script>
    window.onload = function () {
      var show = document.getElementById("show");
      var timer = setInterval(function () {
        show.innerHTML = new Date().toLocaleString();
      }, 1000)
      var btn = document.getElementById("btn");
      // 停止时间 清除定时器
      btn.onclick = function () {
        clearInterval(timer)
      }
      // 弹出广告
      var ad = document.getElementById("ad");//广告
      var x = -400;
      var timer2 = setInterval(function () {
        ad.style.bottom = ++x + "px";
        ad.style.backgroundColor = "#" + Math.floor(Math.random() * 0xffffff).toString(16);
        if (x == 0) {
          clearInterval(timer2)
        }
      }, 10)
      setTimeout(function () {
        ad.style.display = "none"
      }, 5000)
    }
    //

  </script>
</body>

</html>